
#ifndef TERMINAL_CANVAS_H_
#define TERMINAL_CANVAS_H_

#include <stddef.h>
#include <sys/types.h>

#include <string>

#include "buffered_write_sequencer.h"
#include "framebuffer.h"

namespace tv {

// Canvas that can send a framebuffer to a terminal.
class TerminalCanvas {
public:
  // Create a terminal canvas, sending to given file-descriptor.
  explicit TerminalCanvas(BufferedWriteSequencer *write_sequencer);
  TerminalCanvas(const TerminalCanvas &) = delete;
  virtual ~TerminalCanvas();

  virtual int cell_height_for_pixels(int pixels) const = 0;

  // Send frame to terminal. Move to xposition (relative to the left
  // of the screen, and delta y (relative to the current position) first.
  virtual void Send(int x, int dy, const Framebuffer &framebuffer,
                    SeqType sequence_type, Duration end_of_frame) = 0;

  // The following methods add content that is emitted before the next Send()

  void AddPrefixNextSend(const char *data, int len);

  void ClearScreen();
  void CursorOff();
  void CursorOn();

  void MoveCursorDY(int rows); // -: up^, +: downV
  void MoveCursorDX(int cols); // -: <-left, +: right->

protected:
  char *AppendPrefixToBuffer(char *buffer);

  BufferedWriteSequencer *const write_sequencer_; // not owned

private:
  std::string prefix_send_;
};
} // namespace tv

#endif // TERMINAL_CANVAS_H_
